package cn.tedu.csmall.cart.controller;



import cn.tedu.csmall.cart.service.ICartService;
import cn.tedu.csmall.commons.pojo.cart.dto.CartAddDTO;
import cn.tedu.csmall.commons.restful.JsonResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@Api(tags = "购物车模块")
@RequestMapping("/base/cart")
public class CartController {
    @Autowired
    private ICartService cartService;

    //新增商品到购物车
    @PostMapping("/add")
    @ApiOperation("新增商品到购物车")
    public JsonResult cartAdd(CartAddDTO cartAddDTO) {
        cartService.cartAdd(cartAddDTO);
        return JsonResult.ok("新增商品到购物车成功");
    }

    //删除商品
    @PostMapping("/delete")
    @ApiOperation("删除购物车中的商品")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "用户ID", name = "userId", example = "UU100", required = true),
            @ApiImplicitParam(value = "商品编号", name = "commodityCode", example = "PC100", required = true)
    })
    public JsonResult deleteCartByUserIdAndCommodity(String userId, String commodityCode) {
        cartService.deleteCartByUserIdAndCommodityCode(userId, commodityCode);
        return JsonResult.ok("删除购物车中的商品成功");
    }
}
